package com.leonardo.beanme.fields.abs;

import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Item;

import com.leonardo.beanme.fields.InputField;
import com.leonardo.beanme.fields.impl.RadioInput;

public abstract class ChoiceInput implements InputField {

	private ChoiceGroup group;
	
	public ChoiceInput(int choiceType) {
		this.group = new ChoiceGroup("", choiceType);
	}
	
	public void setLabel(String label) {
		group.setLabel(label);
	}
		
	protected int addOption(String op) {
		return group.append(op, null);
	}
	
	protected RadioInput addOptionsTo(RadioInput radio) {
		for(int i = 0; i < group.size(); i++)
			radio.addOption(group.getString(i));
		return radio;
	}
	
	public void clear() {
		if(getGroup().size() > 0)
			group.setSelectedIndex(0, true);
	}
	
	public Item getField() {
		return group;
	}
	
	protected ChoiceGroup getGroup() {
		return group;
	}
		
	public String getLabel() {
		return group.getLabel();
	}
	
	public void setName(String name) {}
	
	public Object getDefaultValue() {
		return null;
	}
	
}
